<?php
if (!defined('IN_DISCUZ')){
	exit('Access Denied');
}

global $_G;

if ($uData)
	showmessage('ban_da_dang_ky_gian_hang', 'shop.php?mod=store&ac=profile&do=update');

$profile['uid'] = intval($_G['uid']);
$profile['dateline'] = $_G['timestamp'];

$submited = submitcheck('submit', 1, $seccodecheck);

// Cac tinh/thanh cua VietNam
$provice = provice();

// Submit form
if ($submited && ($_G['adminid'] != 1)){
	$profile['sid'] = isset($_G['gp_sid']) ? intval($_G['gp_sid']) : $uData['sid'];
	if (intval($profile['sid']) == 0)
		$post_erro['sid'] = 1;

	$profile['shopname'] = isset($_G['gp_shopname']) ? get_str_nohtml($_G['gp_shopname']) : '';
	if (strlen($profile['shopname']) < 3)
		$post_erro['shopname'] = 1;

	$profile['authorname'] = isset($_G['gp_authorname']) ? get_str_nohtml($_G['gp_authorname']) : '';
	if (strlen($profile['authorname']) < 7)
		$post_erro['authorname'] = 1;

	$profile['cardid_number'] = isset($_G['gp_cardid_number']) ? get_str_nohtml($_G['gp_cardid_number']) : '';
	if (strlen($profile['cardid_number']) < 9)
		$post_erro['cardid_number'] = 1;

	$gp['reg_date_number'] = isset($_G['gp_reg_date_number']) ? get_str_nohtml($_G['gp_reg_date_number']) : '';
	if (strlen($gp['reg_date_number']) <= 0)
		$post_erro['reg_date_number'] = 1;

	$gp['date_number'] = explode('/', $gp['reg_date_number']);
	for ($i = 0; $i < count($gp['date_number']); $i++){
		$gp['cardid_date']['bday'] = intval($gp['date_number'][0]);
		$gp['cardid_date']['bmonth'] = intval($gp['date_number'][1]);
		$gp['cardid_date']['byear'] = intval($gp['date_number'][2]);
	}
	$profile['cardid_date'] = addslashes(serialize($gp['cardid_date']));

	$profile['cardid_issuer'] = isset($_G['gp_province']) ? intval($_G['gp_province']) : 0;

	$profile['shopaddr'] = isset($_G['gp_shopaddr']) ? get_str_nohtml($_G['gp_shopaddr']) : '';
	if (strlen($profile['shopaddr']) < 20)
		$post_erro['shopaddr'] = 1;

	$profile['store_province'] = isset($_G['gp_store_province']) ? intval($_G['gp_store_province']) : 0;

	$profile['phonenumber'] = isset($_G['gp_phonenumber']) ? get_str_nohtml($_G['gp_phonenumber']) : '';

	$profile['email'] = isset($_G['gp_email']) ? get_str_nohtml($_G['gp_email']) : '';
	if (!isemail($profile['email']))
		$post_erro['email'] = lang('shop/template', 'erro_email');

	$profile['store_about'] = isset($_G['gp_store_about']) ? get_str_nohtml($_G['gp_store_about']) : '';

	if (empty($uData) && empty($post_erro)){
		$note_values = array(
				'url'=>'shop.php?mod=store&ac=profile&do=update&uid=' . $profile['uid'],
				'actor'=>$_G['username']
		);

		DB::insert('shop_profile', $profile);
		foreach ($NoteToAdmin as $key=>$value){
			notification_add($value, 'shopactive', 'dang_ky_mo_shop', $note_values, 1);
		}
		showmessage('ban_da_dang_ky_gian_hang_thanh_cong_success', 'shop.php?mod=store&ac=profile&do=update');
	}

}

include template('shop/store/reg_store');